package com.jieao.template.config;

import com.jieao.template.entity.pub.JsonData;
import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 404异常处理类
 *
 * @author 姜兆伟
 * @className HttpErrorHandler
 * @date 2019-08-03 14:03
 */
@RestController
public class HttpErrorHandler implements ErrorController
{

    private final static String ERROR_PATH = "/error";

    /**
     * 针对获取页面notFind的处理
     */
    @RequestMapping(value = ERROR_PATH)
    public JsonData error(HttpServletRequest req, HttpServletResponse resp) throws IOException
    {
        return JsonData.notFind();
    }


    /**
     * Returns the path of the error page.
     *
     * @return the error path
     */
    @Override
    public String getErrorPath()
    {
        return ERROR_PATH;
    }
}